const mongolass = require('../lib/mongo')

const User = mongolass.model('User', {
    name: { type: 'string', require: true },
    password: { type: 'string', require: true },
    avatar: { type: 'string', require: true },
    gender: { type: 'string', enum: ['m', 'f', 'x'], default: 'x' },
    bio: { type: 'string', require: true }
})


module.exports = {
    create(user) {
        return User.create(user).exec()
    },
    findUserCount() {
       return User.countDocuments().exec()
    },
    findUserList(param) {
        let count = (param.page - 1) * param.pageSize
        return User.find().skip(count).limit(param.pageSize).exec()
    }
}